import type {
  CollectionDocument,
  WorkspaceDocument,
} from "@app/database/database";
import type {
  Auth,
  Body,
  KeyValueChecked,
  Response,
  StatePartial,
} from "@sparrow/common/types/workspace";

export type UpdateRequestUrlType = (
  url: string,
  effectQueryParams?: boolean,
) => void;
export interface UpdateRequestUrl {
  updateRequestUrl: UpdateRequestUrlType;
}
export type UpdateRequestDescriptionType = (description: string) => void;
export interface UpdateRequestDescription {
  updateRequestDescription: UpdateRequestDescriptionType;
}

export type UpdateRequestNameType = (name: string) => void;
export interface UpdateRequestName {
  updateRequestName: UpdateRequestNameType;
}

export type UpdateRequestMethodType = (method: string) => void;
export interface UpdateRequestMethod {
  updateRequestMethod: UpdateRequestMethodType;
}
export type UpdateHeadersType = (headers: KeyValueChecked[]) => void;
export interface UpdateHeaders {
  updateHeaders: UpdateHeadersType;
}
export type UpdateParamsType = (
  params: KeyValueChecked[],
  effectURL?: boolean,
) => void;
export interface UpdateParams {
  updateParams: UpdateParamsType;
}
export type UpdateAutoGeneratedHeadersType = (
  headers: KeyValueChecked[],
) => void;
export interface UpdateAutoGeneratedHeaders {
  updateAutoGeneratedHeaders: UpdateAutoGeneratedHeadersType;
}
export type UpdateRequestStateType = (state: StatePartial) => void;
export interface UpdateRequestState {
  updateRequestState: UpdateRequestStateType;
}
export type UpdateRequestAuthType = (auth: Auth) => void;
export interface UpdateRequestAuth {
  updateRequestAuth: UpdateRequestAuthType;
}
export type UpdateRequestBodyType = (body: Body) => void;
export interface UpdateRequestBody {
  updateRequestBody: UpdateRequestBodyType;
}
export type UpdateResponseType = (response: Response) => void;
export interface UpdateResponse {
  updateResponse: UpdateResponseType;
}
export type ClearResponseType = () => Promise<void>;
export interface ClearResponse {
  clearResponse: ClearResponseType;
}
export type SendRequestType = () => Promise<void>;

export type CancelRequestType = () => Promise<void>;
export interface SendRequest {
  sendRequest: SendRequestType;
}
export type ReadCollectionType = (uuid: string) => Promise<CollectionDocument>;
export interface ReadCollection {
  readCollection: ReadCollectionType;
}
export type ReadRequestOrFolderInCollectionType = (
  collectionId: string,
  uuid: string,
) => Promise<object>;
export interface ReadRequestOrFolderInCollection {
  readRequestOrFolderInCollection: ReadRequestOrFolderInCollectionType;
}
export type ReadRequestInFolderType = (
  collectionId: string,
  folderId: string,
  uuid: string,
) => Promise<unknown>;
export interface ReadRequestInFolder {
  readRequestInFolder: ReadRequestInFolderType;
}
export type CreateFolderType = (
  workspaceMeta: { id: string; name: string },
  collectionId: string,
  folderName: string,
) => Promise<{ status: string; data?: object; message?: string }>;
export interface CreateFolder {
  createFolder: CreateFolderType;
}

export type CreateCollectionType = (
  workspaceMeta: { id: string; name: string },
  collectionName: string,
) => Promise<{ status: string; data?: object; message?: string }>;
export interface CreateCollection {
  createCollection: CreateCollectionType;
}

export type ReadWorkspaceType = (uuid: string) => Promise<WorkspaceDocument>;
export interface ReadWorkspace {
  readWorkspace: ReadWorkspaceType;
}

export type AddRequestOrFolderInCollectionType = (
  collectionId: string,
  items: object,
) => void;
export interface AddRequestOrFolderInCollection {
  addRequestOrFolderInCollection: AddRequestOrFolderInCollectionType;
}

export type AddCollectionType = (collection: object) => void;
export interface AddCollection {
  addCollection: AddCollectionType;
}

export type AddRequestInFolderType = (
  collectionId: string,
  folderId: string,
  request: object,
) => void;
export interface AddRequestInFolder {
  addRequestInFolder: AddRequestInFolderType;
}

export type SaveRequestType = (
  saveDescriptionOnly?: boolean,
) => Promise<{ status: string; message?: string }>;
export interface SaveRequest {
  saveRequest: SaveRequestType;
}

export type SaveAsRequestType = (
  workspaceMeta: { id: string; name: string },
  path: { name: string; id: string; type: string }[],
  tabName: string,
  description: string,
  type: string,
) => Promise<
  { status: string; message?: string; data?: { id: string } } | unknown
>;
export interface SaveAsRequest {
  saveAsRequest: SaveAsRequestType;
}
